package znbkChangeZsdLearned.presenter;

import znbkListXtfx.ISystemReviewPresenter;
import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.reviewsystem.utils.ToastUtils;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import znbkChangeZsdLearned.api.ZnbkSaveZsdApi;
import znbkChangeZsdLearned.ZnbkSaveLearnedZsdJsonModel;
import znbkTestPaperCtfd.activity.WrongTopicTutoringPaperActivity;
import znbkTestPaperInfor.ZnbkPaperDef;
import znbkTestPaperInfor.ZnbkPaperInfor;
import znbkTestPaperRdtz.activity.HeatPointExtensionPaperActivity;
import znbkTestPaperRdtz.activity.HeatPointExtensionPaperSplActivity;

/**
 * Created by Administrator on 2018\3\19 0019.
 */

public class ZnbkSaveLearnedZsdPresenter implements ISystemReviewPresenter {

    private ILoadPaperView view;
    private int ModelFrom;
    private boolean isFromExit = false;
    int From = -1;

    public ZnbkSaveLearnedZsdPresenter(ILoadPaperView view, int modelFrom) {
        this.view = (ILoadPaperView) view;
        this.ModelFrom = modelFrom;
    }

    @Override
    public void getData(boolean isShowLoading) {
        //  if (isShowLoading) view.showLoading();
        HttpOnNextListener<String> httpOnNextListener = new HttpOnNextListener<String>() {

            @Override
            public void onNext(String saveZsdEntityResult) {
                if(saveZsdEntityResult.equals("true")){

//                    if (isFromExit){
//                        ToastUtils.showShort("数据保存成功");
//                        new Handler().postDelayed(new Runnable() {
//                            @Override
//                            public void run() {
//
//                            }
//                        },600);

//                    }
                }else{
//                    ToastUtils.showShort("数据保存失败! 错误信息"+saveZsdEntityResult);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                //view.showNetError();
                ToastUtils.showShort("数据保存失败!");
            }
        };

        ZnbkSaveZsdApi api = null;
        if(ModelFrom == ZnbkPaperDef.FROM_HEAT_POINT_EXTENSION) {
            api = new ZnbkSaveZsdApi(httpOnNextListener, (HeatPointExtensionPaperActivity)view);
            From = 1;
        }else if(ModelFrom == ZnbkPaperDef.FROM_HEAT_POINT_EXTENSION_SPL) {
            api = new ZnbkSaveZsdApi(httpOnNextListener, (HeatPointExtensionPaperSplActivity)view);
            From = 1;
        }else if(ModelFrom ==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING){
            api = new ZnbkSaveZsdApi(httpOnNextListener, (WrongTopicTutoringPaperActivity)view);
            From = 0;
        }

        api.setmZnbkSaveLearnedZsdEntity(ZnbkSaveLearnedZsdJsonModel.getZnbkSaveLearnedZsdJson(
                ZnbkSaveLearnedZsdJsonModel.getZSDBean(ZnbkPaperInfor.ZSDCode,ZnbkPaperInfor.ZSDName),
                UserInfo.SubjectId,UserInfo.StageNo,UserInfo.StuId,From));

        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }

    public void getData(boolean isShowing ,boolean isFromExit){
        this.isFromExit = isFromExit;
        getData(isShowing);
    }

}